package org.zjt.config;

import com.alibaba.fastjson.JSONObject;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/*@Configuration
@EnableAspectJAutoProxy
@Aspect*/
public class AspectConfig {
    private static final Logger LOGGER = LoggerFactory.getLogger(AspectConfig.class);

    @Before("execution(* org.zjt.controller..*.*(..))")
    public void before(){
        LOGGER.info("---------before------------");
    }

    @After("execution(* org.zjt.controller..*.*(..))")
    public void after(){
        LOGGER.info("---------after------------");
    }

	@Around("execution(* org.zjt.controller..*.*(..))")
	public Object around(ProceedingJoinPoint joinpoint){

        String tranceId = String.format("%s:%s",joinpoint.getSignature(), JSONObject.toJSONString(joinpoint.getArgs()));

        LOGGER.info("---------tranceId------------"+tranceId);

        try {
            return joinpoint.proceed(joinpoint.getArgs());
        }catch (Throwable e){
            e.printStackTrace();
        }
        return null;
	}

    @AfterThrowing(throwing="ex",pointcut="execution(* org.zjt.controller..*.*(..))")
    public void AfterExcepter(Throwable ex){
        LOGGER.info("---------AfterExcepter------------"+ex);
    }
}